<!--

    Copyright © 2016-2024 The Thingsboard Authors

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<ng-container [formGroup]="rpcParametersFormGroup">
  <div class="tb-form-hint tb-primary-fill tb-flex no-padding-top hint-container">
    {{ 'gateway.rpc.hint.opc-method' | translate }}
  </div>
  <mat-form-field class="tb-flex">
    <mat-label>{{ 'gateway.rpc.method' | translate }}</mat-label>
    <input matInput formControlName="method" placeholder="multiply"/>
  </mat-form-field>
  <fieldset class="tb-form-panel stroked arguments-container" formArrayName="arguments">
    <strong>
      <span class="fields-label">{{ 'gateway.rpc.arguments' | translate }}</span>
    </strong>
    <div class="flex flex-1 items-center justify-center gap-2.5"
         *ngFor="let argumentFormGroup of rpcParametersFormGroup.get('arguments')['controls']; let i = index" [formGroup]="argumentFormGroup">
      <div class="tb-form-row column-xs type-container items-center justify-between">
        <div class="tb-required" translate>gateway.type</div>
        <div class="tb-flex no-gap">
          <mat-form-field class="tb-flex no-gap fill-width" appearance="outline" subscriptSizing="dynamic">
            <mat-select formControlName="type">
              <mat-select-trigger>
                <div class="tb-flex align-center">
                  <mat-icon class="tb-mat-18" [svgIcon]="valueTypes.get(argumentFormGroup.get('type').value)?.icon">
                  </mat-icon>
                  <span>{{ valueTypes.get(argumentFormGroup.get('type').value)?.name | translate }}</span>
                </div>
              </mat-select-trigger>
              <mat-option *ngFor="let valueType of valueTypeKeys" [value]="valueType">
                <mat-icon class="tb-mat-20" svgIcon="{{ valueTypes.get(valueType).icon }}">
                </mat-icon>
                <span>{{ valueTypes.get(valueType).name | translate }}</span>
              </mat-option>
            </mat-select>
          </mat-form-field>
        </div>
      </div>
      <div class="tb-form-row column-xs value-container item-center justify-between">
        <div class="tb-required" translate>gateway.value</div>
        <mat-form-field appearance="outline" subscriptSizing="dynamic" class="tb-inline-field tb-suffix-absolute flex">
          <ng-container [ngSwitch]="argumentFormGroup.get('type').value">
            <input *ngSwitchCase="MappingValueType.STRING" matInput required formControlName="string"
                   placeholder="{{ 'gateway.set' | translate }}" />
            <input *ngSwitchCase="MappingValueType.INTEGER" matInput required formControlName="integer" type="number"
                   placeholder="{{ 'gateway.set' | translate }}" />
            <input *ngSwitchCase="MappingValueType.DOUBLE" matInput required formControlName="double" type="number"
                   placeholder="{{ 'gateway.set' | translate }}" />
            <mat-select *ngSwitchCase="MappingValueType.BOOLEAN" formControlName="boolean">
              <mat-option [value]="true">true</mat-option>
              <mat-option [value]="false">false</mat-option>
            </mat-select>
          </ng-container>
          <mat-icon matSuffix
                    matTooltipPosition="above"
                    matTooltipClass="tb-error-tooltip"
                    [matTooltip]="('gateway.value-required') | translate"
                    *ngIf="argumentFormGroup.get(argumentFormGroup.get('type').value).hasError('required')
                              && argumentFormGroup.get(argumentFormGroup.get('type').value).touched"
                    class="tb-error">
            warning
          </mat-icon>
        </mat-form-field>
      </div>
      <button mat-icon-button (click)="removeArgument(i)"
              class="tb-box-button"
              matTooltip="{{ 'gateway.rpc.remove' | translate }}"
              matTooltipPosition="above">
        <mat-icon>delete</mat-icon>
      </button>
    </div>
    <button mat-raised-button
            class="self-start"
            (click)="addArgument()">
      {{ 'gateway.rpc.add-argument' | translate }}
    </button>
  </fieldset>
</ng-container>

